<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_controller extends CI_Controller { 

	private $module = "User";

	public function __construct() {
		parent::__construct();

		load_library($this->module, "user");
		load_library($this->module, "group");
		load_library($this->module, "jury");
		load_library($this->module, "member");
		load_library($this->module, "grade");
		load_library($this->module, "school");

		load_model($this->module, "userModel");
		load_model($this->module, "groupModel");
		load_model($this->module, "gradeModel");
		load_model($this->module, "schoolModel");
	}

	public function index() {

	}

	public function connection() {
		$mon_user = new User($this->input->post('email'),
							 $this->input->post('password')
							 );

		try {
            $mon_user->login();
        }
        catch (Exception $ex) {
            //avant
            //go_and_show_message($ex->getMessage(), "User", "Connexion", "login");

        	// ou sinon
        	//j'envoie le message en session Flash
            show_message($ex->getMessage());
            //et parceque je le veux je redirige
            redirect($this->config->site_url($controller.DIRECTORY_SEPARATOR.$action);
        }

        //avant : dans tous les cas on passe à la suite
		//go_and_show_message("Connexion réussie!", "User", "Connexion", "suite_succes_login", "success", TRUE);

		// ou sinon : on continue
		show_message("Connexion réussie!", "success", TRUE);
		load_view("login_ok");
	}
}